import pika as pika

queue_name = 'prod_jd_equip_warn_msg'
routing_key = 'prod_jd_equip_warn_msg'
exchange = ''

user_info = pika.PlainCredentials('test', '123')
connection = pika.BlockingConnection(pika.ConnectionParameters('10.16.152.203', 5672, '/', user_info))
channel = connection.channel()

# 如果指定的queue不存在，则会创建一个queue，如果已经存在 则不会做其他动作，生产者和消费者都做这一步的好处是
# 这样生产者和消费者就没有必要的先后启动顺序了
channel.queue_declare(queue=queue_name,durable=True)


# 发送消息
def sendMsg():

    body ='{\"DEVICE_CODE\":\"A2211080005160022\",' \
         '\"DATETIME_ACQUISITION\":\"2022-06-06 20:12:14\",' \
         '\"22110800090001010701\":\"5.55\",' \
         '\"22110800090001010702\":\"-4.509\",' \
         '\"22110800090001010703\":\"0.286\",' \
         '\"22110800090001010704\":\"109.1\",' \
         '\"22110800090001010705\":\"18.9\",' \
        '\"22110800090001010706\":\"93.4\",' \
        '\"22110800090001010707\":\"363.5\"}'

    for i in range(1000):
        channel.basic_publish(exchange,routing_key, body)

    connection.close()
    print("发送消息结束")


if __name__ == '__main__':
    sendMsg()